package com.joinlabs.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.joinlabs.entity.Group;
import com.joinlabs.entity.User;
import com.joinlabs.mapper.GroupMapper;
import com.joinlabs.mapper.UserMapper;
import com.joinlabs.service.IUserService;
@Service("userService")
public class UserServiceImpl implements IUserService {
	
	@Resource
	private UserMapper userMapper;
	@Resource
	private GroupMapper groupMapper;
	
	
	@Override
	public User selectByPrimaryKey(Long userId) {
		// TODO Auto-generated method stub
		User user = userMapper.selectByPrimaryKey(userId);
		return user;
	}

	@Override
	public List<User> selectWoGuangZuDeById(long userid, long userid2) {
		// TODO Auto-generated method stub
		List<User> WoGguangzude = userMapper.selectWoGuangZuDeById(userid,userid2);
		return WoGguangzude;
	}

	@Override
	public List<User> selectGongTongById(long userid, long userid2) {
		// TODO Auto-generated method stub
		List<User> GongTonggz = userMapper.selectGongTongById(userid,userid2);
		return GongTonggz;
	}

	@Override
	public List<User> selectGZById(long userid) {
		List<User> GZAll = userMapper.selectGZById(userid);
		for (User user : GZAll) {
			
			Group s =	(Group) groupMapper.selecGroupMinByid(userid,user.getUserId());
			System.out.println("selectGZById让我看看有东西么？"+s);
			
			if(s != null) {
				user.setgroup(s.getFriendgroupName());
				System.out.println(user.getgroup());
			}else {
				user.setgroup(null);
				System.out.println(user.getgroup());
			}
			
		}
		return GZAll;
	}
	
	@Override
	public List<User> selectGZById2(long userid, long userid2) {
		List<User> GZAll = userMapper.selectGZById(userid);
		for (User user : GZAll) {
			
			Group s =	(Group) groupMapper.selecGroupMinByid(userid,user.getUserId());
			System.out.println("selectGZById2让我看看有东西么？"+s);
			
			if(s != null) {
				user.setgroup(s.getFriendgroupName());
				System.out.println(user.getgroup());
			}else {
				user.setgroup(null);
				System.out.println(user.getgroup());
			}
//			List<User> GzBiaoJi = userMapper.selecGuanzuById2333(userid,userid2);
//			System.out.println("*********************************************"+GzBiaoJi);
//			if(GzBiaoJi != null ) {
//				user.setGuanzhuzhuangtai(1);
//				System.out.println(user.getgroup());
//			}else {
//				user.setGuanzhuzhuangtai(0);
//				
//			}
			
		}
		return GZAll;
	}

	@Override
	public List<User> selectFansById(long userid) {
		List<User> Fans = userMapper.selectFansById(userid);
		return Fans;
	}

	@Override
	public List<User> selectGuangZuStateById(long userId, long userId2) {
		List<User> GuangZuState = userMapper.GuangZuStateById(userId,userId2);
		return GuangZuState;
	}

	@Override
	public int serviceAddAttention(long userid, long userid2) {
		// TODO Auto-generated method stub
		int AddAttention = userMapper.AddAttention(userid,userid2);
		
		return AddAttention;
	}

	@Override
	public int serviceDeleteAttention(long userid, long userid2) {
		int AddAttention = userMapper.DeleteAttention(userid,userid2);
		return AddAttention;
	}

	@Override
	public List<User> selectFenZuChengYuanById(long userid, int zuid) {
		List<User> FenZuChengYuan = userMapper.FenZuChengYuanById(userid,zuid);
		for (User user : FenZuChengYuan) {
			
			Group s =	(Group) groupMapper.selecGroupMinByid(userid,user.getUserId());
			System.out.println(s);
			
			if(s != null) {
				user.setgroup(s.getFriendgroupName());
				System.out.println(user.getgroup());
			}else {
				user.setgroup(null);
				System.out.println(user.getgroup());
			}
			
			
		}
		return FenZuChengYuan;
	}

	@Override
	public List<User> selectWeiFenZuChengYuanById(long userid) {
		List<User> WeiFenZuChengYuan = userMapper.selectWeiFenZuChengYuanById(userid);
		
		return WeiFenZuChengYuan;
	}

	@Override
	public List<User> selectAllUser() {
		// TODO Auto-generated method stub
		return userMapper.selectAllUser();
	}

	@Override
	public List<User> selectSomeUser(String userName) {
		// TODO Auto-generated method stub
		return userMapper.selectSomeUsers(userName);
	}

	@Override

	public int updateWeiboNum(long userId) {
		// TODO Auto-generated method stub
		return userMapper.updateWeiboNum(userId);
	}

	public int updateUserService(User user) {
		// TODO Auto-generated method stub
		return userMapper.updateByPrimaryKeySelective(user);
	}

}
